import { useModel } from "umi";
import compress from "gql-compress";

const useCreateDepartment = () => {
    const { graphqlFetch } = useModel("global");

    const createDepartment = async (variables) => {
        let res = await graphqlFetch({
            query: CreateOrganizationDepartment,
            variables,
        });
        return res ? true : false;
    };

    return { createDepartment };
};

const CreateOrganizationDepartment = compress(`mutation MyMutation(
    $oiUuid: UUID!,
    $oiName: String!,
    $oiDesc: String,
    $maInfo: JSON,
    $crInfo: JSON!,
    $oiType: String!,
    $pyName: String!
    $oiRoot: UUID,
) {
    createOrganizationInstitution(
        input: {
            organizationInstitution: {
                oiName: $oiName,
                oiUuid: $oiUuid,
                oiDesc: $oiDesc,
                maInfo: $maInfo,
                crInfo: $crInfo,
                oiType: $oiType,
                pyName: $pyName,
                oiRoot: $oiRoot
            }
        }
    ) {
        clientMutationId
    }
}`);

export default useCreateDepartment;
